/**
 * Copyright (c) 2016-2021 by the respective copyright holders.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 */
package com.zsmartsystems.zigbee.dongle.ember.ezsp.command;

import com.zsmartsystems.zigbee.dongle.ember.ezsp.EzspFrameRequest;
import com.zsmartsystems.zigbee.dongle.ember.ezsp.structure.EmberConcentratorType;
import com.zsmartsystems.zigbee.dongle.ember.internal.serializer.EzspSerializer;

/**
 * Class to implement the Ember EZSP command <b>setConcentrator</b>.
 * <p>
 * Enable/disable concentrator support.
 * <p>
 * This class provides methods for processing EZSP commands.
 * <p>
 * Note that this code is autogenerated. Manual changes may be overwritten.
 *
 * @author Chris Jackson - Initial contribution of Java code generator
 */
public class EzspSetConcentratorRequest extends EzspFrameRequest {
    public static final int FRAME_ID = 0x10;

    /**
     * If this bool is true the concentrator support is enabled. Otherwise is disabled. If this bool
     * is false all the other arguments are ignored.
     * <p>
     * EZSP type is <i>bool</i> - Java type is {@link boolean}
     */
    private boolean enable;

    /**
     * Must be either EMBER_HIGH_RAM_CONCENTRATOR or EMBER_LOW_RAM_CONCENTRATOR. The former
     * is used when the caller has enough memory to store source routes for the whole network. In that
     * case, remote nodes stop sending route records once the concentrator has successfully
     * received one. The latter is used when the concentrator has insufficient RAM to store all
     * outbound source routes. In that case, route records are sent to the concentrator prior to
     * every inbound APS unicast.
     * <p>
     * EZSP type is <i>EmberConcentratorType</i> - Java type is {@link EmberConcentratorType}
     */
    private EmberConcentratorType concentratorType;

    /**
     * The minimum amount of time that must pass between MTORR broadcasts.
     * <p>
     * EZSP type is <i>uint16_t</i> - Java type is {@link int}
     */
    private int minTime;

    /**
     * The maximum amount of time that can pass between MTORR broadcasts.
     * <p>
     * EZSP type is <i>uint16_t</i> - Java type is {@link int}
     */
    private int maxTime;

    /**
     * The number of route errors that will trigger a re-broadcast of the MTORR.
     * <p>
     * EZSP type is <i>uint8_t</i> - Java type is {@link int}
     */
    private int routeErrorThreshold;

    /**
     * The number of APS delivery failures that will trigger a re-broadcast of the MTORR.
     * <p>
     * EZSP type is <i>uint8_t</i> - Java type is {@link int}
     */
    private int deliveryFailureThreshold;

    /**
     * The maximum number of hops that the MTORR broadcast will be allowed to have. A value of 0 will be
     * converted to the EMBER_MAX_HOPS value set by the stack.
     * <p>
     * EZSP type is <i>uint8_t</i> - Java type is {@link int}
     */
    private int maxHops;

    /**
     * Serialiser used to serialise to binary line data
     */
    private EzspSerializer serializer;

    /**
     * Request constructor
     */
    public EzspSetConcentratorRequest() {
        frameId = FRAME_ID;
        serializer = new EzspSerializer();
    }

    /**
     * If this bool is true the concentrator support is enabled. Otherwise is disabled. If this bool
     * is false all the other arguments are ignored.
     * <p>
     * EZSP type is <i>bool</i> - Java type is {@link boolean}
     *
     * @return the current enable as {@link boolean}
     */
    public boolean getEnable() {
        return enable;
    }

    /**
     * If this bool is true the concentrator support is enabled. Otherwise is disabled. If this bool
     * is false all the other arguments are ignored.
     *
     * @param enable the enable to set as {@link boolean}
     */
    public void setEnable(boolean enable) {
        this.enable = enable;
    }

    /**
     * Must be either EMBER_HIGH_RAM_CONCENTRATOR or EMBER_LOW_RAM_CONCENTRATOR. The former
     * is used when the caller has enough memory to store source routes for the whole network. In that
     * case, remote nodes stop sending route records once the concentrator has successfully
     * received one. The latter is used when the concentrator has insufficient RAM to store all
     * outbound source routes. In that case, route records are sent to the concentrator prior to
     * every inbound APS unicast.
     * <p>
     * EZSP type is <i>EmberConcentratorType</i> - Java type is {@link EmberConcentratorType}
     *
     * @return the current concentratorType as {@link EmberConcentratorType}
     */
    public EmberConcentratorType getConcentratorType() {
        return concentratorType;
    }

    /**
     * Must be either EMBER_HIGH_RAM_CONCENTRATOR or EMBER_LOW_RAM_CONCENTRATOR. The former
     * is used when the caller has enough memory to store source routes for the whole network. In that
     * case, remote nodes stop sending route records once the concentrator has successfully
     * received one. The latter is used when the concentrator has insufficient RAM to store all
     * outbound source routes. In that case, route records are sent to the concentrator prior to
     * every inbound APS unicast.
     *
     * @param concentratorType the concentratorType to set as {@link EmberConcentratorType}
     */
    public void setConcentratorType(EmberConcentratorType concentratorType) {
        this.concentratorType = concentratorType;
    }

    /**
     * The minimum amount of time that must pass between MTORR broadcasts.
     * <p>
     * EZSP type is <i>uint16_t</i> - Java type is {@link int}
     *
     * @return the current minTime as {@link int}
     */
    public int getMinTime() {
        return minTime;
    }

    /**
     * The minimum amount of time that must pass between MTORR broadcasts.
     *
     * @param minTime the minTime to set as {@link int}
     */
    public void setMinTime(int minTime) {
        this.minTime = minTime;
    }

    /**
     * The maximum amount of time that can pass between MTORR broadcasts.
     * <p>
     * EZSP type is <i>uint16_t</i> - Java type is {@link int}
     *
     * @return the current maxTime as {@link int}
     */
    public int getMaxTime() {
        return maxTime;
    }

    /**
     * The maximum amount of time that can pass between MTORR broadcasts.
     *
     * @param maxTime the maxTime to set as {@link int}
     */
    public void setMaxTime(int maxTime) {
        this.maxTime = maxTime;
    }

    /**
     * The number of route errors that will trigger a re-broadcast of the MTORR.
     * <p>
     * EZSP type is <i>uint8_t</i> - Java type is {@link int}
     *
     * @return the current routeErrorThreshold as {@link int}
     */
    public int getRouteErrorThreshold() {
        return routeErrorThreshold;
    }

    /**
     * The number of route errors that will trigger a re-broadcast of the MTORR.
     *
     * @param routeErrorThreshold the routeErrorThreshold to set as {@link int}
     */
    public void setRouteErrorThreshold(int routeErrorThreshold) {
        this.routeErrorThreshold = routeErrorThreshold;
    }

    /**
     * The number of APS delivery failures that will trigger a re-broadcast of the MTORR.
     * <p>
     * EZSP type is <i>uint8_t</i> - Java type is {@link int}
     *
     * @return the current deliveryFailureThreshold as {@link int}
     */
    public int getDeliveryFailureThreshold() {
        return deliveryFailureThreshold;
    }

    /**
     * The number of APS delivery failures that will trigger a re-broadcast of the MTORR.
     *
     * @param deliveryFailureThreshold the deliveryFailureThreshold to set as {@link int}
     */
    public void setDeliveryFailureThreshold(int deliveryFailureThreshold) {
        this.deliveryFailureThreshold = deliveryFailureThreshold;
    }

    /**
     * The maximum number of hops that the MTORR broadcast will be allowed to have. A value of 0 will be
     * converted to the EMBER_MAX_HOPS value set by the stack.
     * <p>
     * EZSP type is <i>uint8_t</i> - Java type is {@link int}
     *
     * @return the current maxHops as {@link int}
     */
    public int getMaxHops() {
        return maxHops;
    }

    /**
     * The maximum number of hops that the MTORR broadcast will be allowed to have. A value of 0 will be
     * converted to the EMBER_MAX_HOPS value set by the stack.
     *
     * @param maxHops the maxHops to set as {@link int}
     */
    public void setMaxHops(int maxHops) {
        this.maxHops = maxHops;
    }

    @Override
    public int[] serialize() {
        // Serialize the header
        serializeHeader(serializer);

        // Serialize the fields
        serializer.serializeBool(enable);
        serializer.serializeEmberConcentratorType(concentratorType);
        serializer.serializeUInt16(minTime);
        serializer.serializeUInt16(maxTime);
        serializer.serializeUInt8(routeErrorThreshold);
        serializer.serializeUInt8(deliveryFailureThreshold);
        serializer.serializeUInt8(maxHops);
        return serializer.getPayload();
    }

    @Override
    public String toString() {
        final StringBuilder builder = new StringBuilder(229);
        builder.append("EzspSetConcentratorRequest [networkId=");
        builder.append(networkId);
        builder.append(", enable=");
        builder.append(enable);
        builder.append(", concentratorType=");
        builder.append(concentratorType);
        builder.append(", minTime=");
        builder.append(minTime);
        builder.append(", maxTime=");
        builder.append(maxTime);
        builder.append(", routeErrorThreshold=");
        builder.append(routeErrorThreshold);
        builder.append(", deliveryFailureThreshold=");
        builder.append(deliveryFailureThreshold);
        builder.append(", maxHops=");
        builder.append(maxHops);
        builder.append(']');
        return builder.toString();
    }
}
